﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace HKTools
{
    public class HK_MenuCtrl : MonoBehaviour
    {
        [SerializeField] Scrollbar scrollBar;

        List<GameObject> itemPanelList;

        [SerializeField] GameObject menuItem_L1;
        [SerializeField] GameObject menuItem_L2;
        [SerializeField] GameObject menuItem_L3;

        [SerializeField] Transform content;

        void Awake()
        {
            itemPanelList = new List<GameObject>();
        }

        void Start()
        {
            // 新建一级菜单
            for (int i = 0; i < 16; i++)
            {
                GameObject newItemPanel = Instantiate(menuItem_L1);
                itemPanelList.Add(newItemPanel);
                newItemPanel.GetComponent<HK_MenuItem>().SetParent(content);
                newItemPanel.GetComponent<HK_MenuItem>().InitPanelContent(new HK_MenuData("一级菜单" + i, 1));
            }

            // 新建二级菜单
            for (int i = 0; i < 6; i++)
            {
                GameObject newItemPanel = Instantiate(menuItem_L2);
                itemPanelList.Add(newItemPanel);
                newItemPanel.GetComponent<HK_MenuItem>().SetParent(itemPanelList[i].GetComponent<HK_MenuItem>());
                newItemPanel.GetComponent<HK_MenuItem>().InitPanelContent(new HK_MenuData("二级菜单" + i, 2));
            }

            // 新建三级菜单
            for (int i = 0; i < 3; i++)
            {
                GameObject newItemPanel = Instantiate(menuItem_L3);
                itemPanelList.Add(newItemPanel);
                newItemPanel.GetComponent<HK_MenuItem>().SetParent(itemPanelList[21].GetComponent<HK_MenuItem>());
                newItemPanel.GetComponent<HK_MenuItem>().InitPanelContent(new HK_MenuData("三级菜单" + i, 3));
            }

            scrollBar.value = 0;
        }
    }
}